package net.ithe.controller;

import lombok.extern.slf4j.Slf4j;
import net.ithe.pojo.PageResult;
import net.ithe.pojo.Result;
import net.ithe.pojo.Student;
import net.ithe.pojo.StudentQueryParam;
import net.ithe.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RequestMapping("/students")
@RestController
public class StudentController {
    @Autowired
    private StudentService studentService;
    @GetMapping
    public Result page(StudentQueryParam studentQueryParam){
        log.info("分页查询学生数据,参数:{}",studentQueryParam);
        PageResult<Student> pageResult=studentService.page(studentQueryParam);
        return Result.success(pageResult);
    }
    @DeleteMapping("/{ids}")
    public Result delete(@PathVariable("ids") List<Integer> ids) {
        studentService.delete(ids);
        return Result.success();
    }
    @PostMapping
    public Result save(@RequestBody Student student){
        log.info("保存员工数据,参数:{}",student);
        studentService.save(student);
        return Result.success();
    }
    @GetMapping("/{id}")
    public Result getInfo(@PathVariable Integer id) {
        log.info("获取员工信息,id:{}",id);
        Student student = studentService.getById(id);
        return Result.success(student);
    }
    @PutMapping
    public Result update(@RequestBody Student student) {
        log.info("更新学员信息,参数:{}",student);
        studentService.update(student);
        return Result.success();
    }
    @PutMapping("/violation/{id}/{score}")
    public Result updateViolation(@PathVariable Short id,@PathVariable Short score) {
        log.info("更新学员违纪信息,参数:{}",id);
        studentService.updateViolation(id,score);
        return Result.success();
    }
}
